package cn.chencaiju.day03;

import org.junit.Test;

public class PrintShape {
	//打印X形
	public void printXShape(int size) {
		for(int i=-size;i<=size;i++) {
			for(int j=size;j>=-size;j--) {
				if(i==j||i==-j) {
					System.out.print("* ");
				}else {
					System.out.print("  ");
				}
			}
			System.out.println();
		}
	}
	//打印蝴蝶结
	public void printBowknot(int size) {
		for(int i=-size;i<=size;i++) {
			for(int j=size;j>=-size;j--) {
				if(Math.abs(i)<=Math.abs(j)) {
					System.out.print("* ");
				}else {
					System.out.print("  ");
				}
			}
			System.out.println();
		}
	}
	//打印菱形
	public void printDiamond(int size) {
		for(int i=-size;i<=size;i++) {
			for(int j=size;j>=-size;j--) {
				if((i+j)>=(2*i-2)&&(i+j)<=(2*i+2)) {
					if((i+j)>=-2&&(i+j)<=2) {
						System.out.print("* ");
					}else {
						System.out.print("  ");
					}
				}
			}
			System.out.println();
		}
	}
	@Test public void testPrintXShape() {
		printXShape(2);
	}
	@Test public void testPrintBowknot() {
		printBowknot(2);
	}
	@Test public void testPrintDiamond() {
		printDiamond(2);
	}
}
